package com.flyco.modules.report.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.flyco.common.util.oConvertUtils;
import com.flyco.modules.report.entity.ReportSqlConfig;
import com.flyco.modules.report.mapper.ReportSqlConfigMapper;
import com.flyco.modules.report.service.IReportSqlConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;

/**
 * @Description: 报表配置
 * @Author: flyco
 * @Date:   2019-12-11
 * @Version: V1.0
 */
@Service
public class ReportSqlConfigServiceImpl extends ServiceImpl<ReportSqlConfigMapper, ReportSqlConfig> implements IReportSqlConfigService {

    @Override
    public ReportSqlConfig queryByCode(String code) {
        LambdaQueryWrapper<ReportSqlConfig> query = new LambdaQueryWrapper<>();
        query.eq(ReportSqlConfig::getCode, code);
        query.eq(ReportSqlConfig::getSourceSystem,"admin");
        ReportSqlConfig reportSqlConfig = this.getOne(query);
        return reportSqlConfig;
    }

    public List<ReportSqlConfig> queryShowConfig(String url) {
        LambdaQueryWrapper<ReportSqlConfig> query = new LambdaQueryWrapper<>();
        query.select(ReportSqlConfig::getId, ReportSqlConfig::getCode, ReportSqlConfig::getName, ReportSqlConfig::getType, ReportSqlConfig::getPageData);
        query.eq(ReportSqlConfig::getShowStatus, 1);
        query.eq(ReportSqlConfig::getSourceSystem,"admin");
        if (oConvertUtils.isNotEmpty(url)) {
            query.eq(ReportSqlConfig::getUrl, url);
        }
        query.orderByAsc(ReportSqlConfig::getSort);
        List<ReportSqlConfig> configList = this.list(query);
        return configList;
    }
}
